import { formatTime, calculateDays } from '@/utils/utils.js'
export default {
  data() {
    return {
      index: -1,
      picker: [
        {
          type: 0,
          name: '日利率'
        },
        {
          type: 1,
          name: '月利率'
        },
        {
          type: 2,
          name: '年利率'
        }
      ],
      oldTax: '',
      appointTax: '',
      overdueDays: 0,
      taxCount: 0,
      startDate: '',
      endDate: '',
      resultShow: false
    }
  },
  watch: {

  },
  methods: {

    //利率计算方式
    PickerChange(e) {
      this.index = e.detail.value
    },

    //起算日期
    startDateChange(e) {
      this.startDate = e.detail.value
    },

    //截止日期
    endDateChange(e) {
      this.endDate = e.detail.value
    },

    //重置
    resetBtn() {
      this.resultShow = false
      this.oldTax = ''
      this.index = -1
      this.appointTax = ''
    },

    //计算
    countBtn() {
      if (this.oldTax == '') {
        this.$tools.msg('请填写违约本金')
        return
      }
      if (this.index == -1) {
        this.$tools.msg('请选择利率计算方式 ')
        return
      }
      if (this.appointTax == '') {
        this.$tools.msg('请填写约定利率')
        return
      }
      this.resultShow = true
      this.overdueDays = calculateDays(this.startDate, this.endDate)
      const a = this.appointTax / 100
      if (this.index == 0) {
        this.taxCount = (this.oldTax * this.overdueDays * a).toFixed(2)
      } else if (this.index == 1) {
        this.taxCount = (this.oldTax * this.overdueDays * a * 12 / 365).toFixed(2)
      } else if (this.index == 2) {
        this.taxCount = (this.oldTax * this.overdueDays * a / 365).toFixed(2)
      }
      console.log(a)
    }
  },
  onLoad(options) {
    const date = new Date()
    this.startDate = formatTime(date, 'Y-M-D')
    this.endDate = formatTime(date, 'Y-M-D')
  },
}